package com.scau.XFourPOS.action;
import com.scau.XFourPOS.model.Product;
import com.opensymphony.xwork2.ActionSupport;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.scau.XFourPOS.model.*;
import com.scau.XFourPOS.service.CustomerService;
import com.scau.XFourPOS.service.ProductService;
import com.scau.XFourPOS.utils.PageUtils;

/**
 * 类名：ProductAction
 * 类描述：商品控制器
 * 创建人：庄祥鹏       
 * */
@Controller
@ParentPackage("struts-default")
@Namespace("/")
public class ProductAction extends ActionSupport {
	
	private Product product;
	/**
	 * 产品类测试
	 */
	@Resource
	ProductService ps;
	@Action(value = "productAction", results = {
			@Result(name = SUCCESS, location = "/yes.jsp"),
			@Result(name = INPUT, location = "/no.jsp") })
	public String testGetAll() {
		Product product=new Product();
		product.setDescription("3d;alfkj");
		Product pd=product;
		pd.setName("name");
		ps.saveOrUpdateEntity(product);
		ps.saveOrUpdateEntity(pd);
		
		ps.deleteEntityById(1);
		return SUCCESS;
	}
	/**
	 * 客户类测试
	 */
	@Resource
	CustomerService cs;
	@Action(value = "customerAction", results = {
			@Result(name = SUCCESS, location = "/yes.jsp"),
			@Result(name = INPUT, location = "/no.jsp") })
	public String hello() {
		Customer customer=new Customer();
		customer.setProductAddr("tianhe");
		customer.setProductNO("tiaoxingma");
		Customer pd=customer;
		cs.saveOrUpdateEntity(customer);
		return SUCCESS;
	}
	
	
	
	//增加产品
	public String saveProduct(){
		ps.saveOrUpdateEntity(product);
		return  "success";
	}
	
	
	//删除产品
	public String deleteProduct(Product product){
		ps.deleteEntity(product);
		return  "success";
	}
	
	public String deleteProductById(int id){
		ps.deleteEntityById(id);
		return  "success";
	}
	
	
	//查找产品
	public String searchProduct(int id){
		ps.loadEntityById(id);
		return  "success";
	}
	
	//修改产品信息
	public String updateProduct(){
		ps.saveOrUpdateEntity(product);
		return  "success";
	}
	
}
